package dataInit

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/schema"
	"gowork/microSignalSMSSending/model"
	"time"
)

var (
	Db *gorm.DB
	err error
)

func init() {
	dsn := "root:new_password@tcp(127.0.0.1:3306)/micro_signal_s_m_s_sending?charset=utf8mb4&parseTime=True&loc=Local"
	Db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
		NamingStrategy: schema.NamingStrategy{
			SingularTable: true,
		},
	})
	if err != nil{
		panic("db error")
	}

	sqlDb, pErr := Db.DB()
	if pErr != nil{
		panic("db error")
	}
	sqlDb.SetMaxIdleConns(10)
	sqlDb.SetMaxOpenConns(100)
	sqlDb.SetConnMaxLifetime(time.Hour)

	fmt.Println("同步表结构。。。。。。。。。。。")
	Db.AutoMigrate(&model.Adviser{}, &model.AuthorizationRecords{}, &model.Customer{}, &model.DistributionRecords{}, &model.CallLog{}, &model.SMSRecord{}, &model.SMSTemplate{}, &model.SendingModeRecord{}, &model.AdviserWeChatInfo{})
}
